<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>login</title>

    <!-- Bootstrap -->
    <link rel="stylesheet" href="./commons/bootstrap-3.3.7-dist/css/bootstrap.min.css">
    <!-- 加载bootstrap-select -->
    <link href="./commons/bootstrap-select-1.13.9-dist/css/bootstrap-select.min.css" rel="stylesheet">
    <!-- 加载bootstrap-treeview -->
    <link href="./commons/bootstrap-treeview-1.2.0-dist/bootstrap-treeview.min.css" rel="stylesheet">
    <link rel="stylesheet" href="./commons/css/currency.css">



    <!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 -->
    <!-- 警告：通过 file:// 协议（就是直接将 html 页面拖拽到浏览器中）访问页面时 Respond.js 不起作用 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<nav class="navbar navbar-default" role="navigation">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#example-navbar-collapse">
                <span class="sr-only">切换导航</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">CIMS-校园即时通讯系统</a>
        </div>
    </div>
</nav>

<div class="container">
    <div class="page-header">
        <h3 style="align-content: center">CIMS-校园即时通讯系统</h3>
    </div>
    <div style="padding: 0px 100px 10px;">
        <form class="bs-example bs-example-form " role="form"  method="post">
            <div class="input-group input-group-lg">
                <span class="input-group-addon">用户名</span>
                <input id="userName" name="userName" type="text" class="form-control" placeholder="请输入用户名">
            </div>
            <br>
            <div class="input-group input-group-lg">
                <span class="input-group-addon">密&nbsp;码</span>
                <input id="userPassword_login_input" type="password" name="userPassword" class="form-control" aria-label="Amount (to the nearest dollar)">
                <span id="passwordVisible_login_span" class="input-group-addon"><i class="glyphicon glyphicon-eye-close" aria-hidden="true"></i></span>
            </div>
            <br>
            <button class="btn btn-primary btn-lg btn-block" id="submit_login_btn" type="button"><span
                    class="glyphicon glyphicon-save">登录</span></button>
        </form>
    </div>

</div>

<div class="footer ">
    <div class="container">
        <div class="row footer-bottom">
            <ul class="list-inline text-center">
                <li> Campus Instant Messaging System @2020 杭州职业技术学院 软件技术专业</li>
            </ul>
        </div>
    </div>
</div>
<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<!-- Bootstrap -->
<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
<script src="./commons/js/jquery.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="./commons/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script src="./commons/bootstrap-treeview-1.2.0-dist/bootstrap-treeview.min.js"></script>
<script src="./commons/bootstrap-select-1.13.9-dist/js/bootstrap-select.min.js"></script>



<script>
    $("#passwordVisible_login_span").click(function () {
        var flg=$(this).attr("visible") == 0;
        var i = $("<i></i>")

        $(this).empty();
        if (flg){
            $("#userPassword_login_input").attr("type","text");
            i.addClass("glyphicon glyphicon-eye-open");
            $(this).append(i);
            $(this).attr("visible",1);
        }else{
            $("#userPassword_login_input").attr("type","password");
            i.addClass("glyphicon glyphicon-eye-close");
            $(this).append(i);
            $(this).attr("visible",0);
        }
    });

    //用户登录
    $("#submit_login_btn").click(function () {
        alert($("form").serialize())

        //登录
        $.ajax({
            url: "user/login",
            data: $("form").serialize(),
            type: "post",
            dataType: "json",
            success: function (result) {
                if (result.code == 100) {
                    alert(result.msg);
                    window.location.href = result.target;
                } else {
                    if (result.extend.fieldErrors.empName != undefined) {
                        show_validation_msg("#userName_login_input", "error", result.extend.fieldErrors.userName);
                    }
                }

            }
        });
    })

    function show_validation_msg(element, status, msg) {
        var ctrl = $(element).parents("div.form-group");
        ctrl.removeClass("has-success has-error");
        if ("success" == status) {
            ctrl.addClass("has-success");
        } else {
            ctrl.addClass("has-error");
        }
        ctrl.find("span.help-block").text(msg);
    }

</script>
</body>
</html>
